< previous page page_166 next page >

Page 166
When a C header has a variable type bracketed by parentheses, it means the variable that follows is coerced (or cast) into the specified type. The variables are not converted from one type to anotherrather, the compiler simply treats the data as if it belongs to the new type. So ((WORD)32517) means to treat the value 32517 as an unsigned integer.
The entire macro can be interpreted as follows:
1. Take the integer value "i" and treat it as an unsigned 16-bit number.
2. Take that number and treat it as a 32-bit number (setting the high 16 bits to 0).
3. Take the 32-bit unsigned number and treat it as a pointer to a string (even though it is not a pointer at all).
You may be wondering how can you possibly pass a number that is not a pointer to an API function that expects a string parameter? The answer can be found in the somewhat cryptic description of the lpIconName parameter that you read earlier:
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
Points to a null-terminated string that contains the name of the icon resource to be loaded. Alternatively, this parameter can contain the resource identifier in the low-order word and 0 in the high-order word. Use the MAKEINTRESOURCE macro to create this value.
0166-01.gif
Figure S6-1:
Passing the IDI_ASTERISK resource identifier to the
LoadIcon function
You see, the lpIconName parameter is designed to handle two types of parameters. If the LoadIcon function sees that the high 16 bits is 0, the function assumes that you are passing a numeric identifier to an icon resource. If the high 16 bits contain data, the function assumes you are passing a pointer to a NULL-terminated string. Figure S6-1 shows what gets passed to the function when the constant value is set to IDI_ASTERISK (32516). As you can see, even though the compiler is told to interpret the value of the constant as a string pointer, the value remains unchanged and is passed directly to the LoadIcon function.

 
< previous page page_166 next page >